<script type="text/javascript" src="<?=base_url()?>resource/plugins/My97DatePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<?=base_url()?>resource/js/layer/layer.js"></script>
<script type="text/javascript" src="<?=base_url()?>resource/js/layer/extend/layer.ext.js"></script>
<script type="text/javascript" src="<?=base_url()?>resource/js/echarts.js"></script>
<script type="text/javascript">
    $(function(){
        trbgmoves('#d3dff2');
        var num=0;
        var num2=0;
        var trs=$('#tongji').find("tr");
        var rows=$('#tongji').find("tr").length;
        for(var i=1;i<rows;i++){
            num+=parseInt($('#qxl'+i).text());
            num2+=parseInt($('#hxl'+i).text());
            var st=parseInt(trs.eq(i).find("td").eq(8).text());
            var st2=parseInt(trs.eq(i).find("td").eq(10).text());
            if(st > 0){
                trs.eq(i).find("td").eq(8).css('color','red');
                $("#tongji").prepend(trs.eq(i));
            }
            if(st2 > 0){
                trs.eq(i).find("td").eq(10).css('color','red');
            }
        }
        $("#tongji").prepend(trs.eq(0));
        $('#qxl').html($('#qxl').text()+"：<span style='color: red'>"+num+"</span><br>截止日期：<?=$frontTime?>");
        $('#hxl').html($('#hxl').text()+"：<span style='color: red'>"+num2+"</span><br>截止日期：<?=$maxTime?>");
    });
    function shit(){
        var stime=$('#startTime').val();
        var etime=$('#endTime').val();
        stime=Date.parse(new Date(stime))/1000;
        etime=Date.parse(new Date(etime))/1000;
        if(stime > etime){
            alert('！！！！开始时间不能大于结束时间');
            return false;
        }
    }
    function tjbb(){
        layer.tab({
            area: ['1030px', '680px'],
            tab: [{
                title: '日维保申请量',
                content: "<div id='main' style='height:600px;width: 1000px;'></div>"
            }, {
                title: '日维修需求量',
                content: '暂未开放'
            }]
        });
        var myChart = echarts.init(document.getElementById('main'));
        myChart.showLoading();
        $.post("<?=blang_url('ajax/ajax/LineChartUpdate')?>",{},function(data){
            var data=JSON.parse(data);
            myChart.hideLoading();
            // 基于准备好的dom，初始化echarts实例
            var option = {

                title: {
                    text: '速卖通维保数据',
                    subtext: '数据来自丹宏昊天网络科技有限公司'
                },
                tooltip: {
                    trigger: 'axis'
                },
                legend: {
                    data:['俄罗斯','西班牙','美国','德国','英国']
                },
                toolbox: {
                    show: true,
                    feature: {
                        dataZoom: {},
                        dataView: {readOnly: false},
                        magicType: {type: ['line', 'bar']},
                        restore: {},
                        saveAsImage: {}
                    }
                },
                xAxis:  {
                    type: 'category',
                    boundaryGap: false,
                    data: data['times']//['周一','周二','周三','周四','周五','周六','周日']
                },
                yAxis: {
                    type: 'value',
                    axisLabel: {
                        formatter: '{value}'
                    }
                },
                dataZoom:{
                    type:'slider'
                },
                series: [
                    {
                        name:'西班牙',
                        type:'line',
                        data:data['es'],//[11, 11, 15, 13, 12, 13, 10],
                        markPoint: {
                            data: [
                                {type: 'max', name: '最大值'},
                                {type: 'min', name: '最小值'}
                            ]
                        },
                        markLine: {
                            data: [
                                {type: 'average', name: '平均值'}
                            ]
                        }
                    },
                    {
                        name:'俄罗斯',
                        type:'line',
                        data:data['ru'],//[1, 8, 2, 5, 3, 2, 0],
                        markPoint: {
                            data: [
                                {type: 'max', name: '最大值'},
                                {type: 'min', name: '最小值'}
                            ]
                        },
                        markLine: {
                            data: [
                                {type: 'average', name: '平均值'}
                            ]
                        }
                    },
                    {
                        name:'美国',
                        type:'line',
                        data:data['us'],//[1, 4, 2, 5, 6, 2, 0],
                        markPoint: {
                            data: [
                                {type: 'max', name: '最大值'},
                                {type: 'min', name: '最小值'}
                            ]
                        },
                        markLine: {
                            data: [
                                {type: 'average', name: '平均值'}
                            ]
                        }
                    },
                    {
                        name:'德国',
                        type:'line',
                        data:data['de'],//[1, 3, 2, 5, 9, 2, 10],
                        markLine: {
                            data: [
                                {type: 'average', name: '平均值'}
                            ]
                        }
                    },
                    {
                        name:'英国',
                        type:'line',
                        data:data['uk'],//[9, 6, 2, 5, 5, 2, 9],
                        markLine: {
                            data: [
                                {type: 'average', name: '平均值'}
                            ]
                        }
                    }
                ]
            };
            // 使用刚指定的配置项和数据显示图表。
            myChart.setOption(option);
        });
    }
    function skuview(band,model){
        layer.open({
            type: 1, //page层
            area: ['600px', '100px'],
            title: band+'  '+model,
            content: "<div id='skudiv' style='text-align: center;margin-top: 18px;'>sku:<input id='skulist' type='text' style='width: 500px'></div>"
        });
        $.ajax({
            type:"post",
            cache:false,
            url:"<?=blang_url('ajax/ajax/getsku/')?>",
            data:{'band':band,'model':model},
            beforeSend:function(){
                $("#skudiv").html("<img src='/resource/images/ajax-loader.gif'>"+$("#skudiv").html());
            },
            success:function(data){
                $("#skudiv").html("sku:<input id='skulist' type='text' style='width: 500px'>");
                $('#skulist').val(data);
            }
        });
    }
</script>
<!--top结束-->
<div class="mian">
    <div class="mian1">
        <div class="mian2">
            <!--left start-->
            <?php $this->load->view('defaults/common/left');?>
            <!--left end-->

            <!--right start-->
            <div class="right">
                <!--breadcrumb start-->
                <div class="righta"> <h1>数据从2015-10-30开始</h1></div>
                <!--breadcrumb end-->

                <!-- contents start -->
                <div id="contents">
                    <div id="ct_search">
                        <form action="<?=blang_url('orders/AliExpress/GetAliExpressBrandSalesList')?>" method="post" name="searchform" >
                            <table id="search_tb">
                                <tr>
                                    <td >
                                        <input name="brand" value="" placeholder="<?=lang('smtpp')?>" />&nbsp;
                                        <input name="model" value="" placeholder="<?=lang('smtxh')?>" />
                                        <?=lang('smtgj')?>：<select name="country">
                                            <option value=""><?=lang('smtqxzgj')?></option>
                                            <?php foreach($countryList as $row):?>
                                                <option value="<?=$row['site_prefix']?>"><?=$row['site_prefix']?></option>
                                            <?php endforeach;?>
                                        </select>
                                        <input type="submit" name="searchSubmit" value=" <?=lang('smtcx')?> " onclick="return shit()"/>
                                        &nbsp;&nbsp;&nbsp;&nbsp;<input type="button" id="xstjbb" value="查看综合统计报表" onclick="tjbb()">
                                        &nbsp;&nbsp;&nbsp;&nbsp;<a href="<?=blang_url('orders/AliExpress/ExportAliExpressSales'.$str) ?>">导出数据</a>
                                    </td>
                                </tr>
                            </table>
                        </form>
                    </div>
                    <div class="ct_content">
                        <table id="tongji">
                            <tr>
                                <th><?=lang('smtpp')?></th>
                                <th><?=lang('smtxh')?></th>
                                <th><?=lang('smtgj')?></th>
                                <th id="qxl"><?=lang('smtqxl')?></th>
                                <th id="hxl"><?=lang('smtlzhxl')?></th>
                                <th><?=lang('smtxzl')?></th>
                                <th><?=lang('smtzzl')?></th>
                                <th>LCM</th>
                                <th>LCM+</th>
                                <th>camera</th>
                                <th>camera+</th>
                            </tr>
                            <?php $i=0;foreach($salesList as $key=>$v):$i++;?>
                                <tr class="moves" align="center" id="xiao<?=$i?>" ondblclick="skuview('<?=$v['brand']?>','<?=$v['model']?>')">
                                    <td><?=$v['brand']?></td>
                                    <td><?=$v['model']?></td>
                                    <td><?=$v['country']?></td>
                                    <td id="qxl<?=$i?>"><?=$v['frontNum']?></td>
                                    <td id="hxl<?=$i?>"><?=$v['laterNum']?></td>
                                    <td><?=$v['laterNum']-$v['frontNum']?></td>
                                    <td><?=$v['rate']?></td>
                                    <td><?=$v['laterNum']*0.06<2?2:floor($v['laterNum']*0.06)?></td>
                                    <td><?=$v['pcmAdd']<2 && $v['pcmAdd']!=0?2:$v['pcmAdd']?></td>
                                    <td><?=$v['laterNum']*0.02<2?1:floor($v['laterNum']*0.02)?></td>
                                    <td><?=$v['cameraAdd']<1 && $v['cameraAdd']!=0?1:$v['pcmAdd']?></td>
                                </tr>
                            <?php endforeach; ?>
                        </table>
                    </div>
                </div>
                <!-- contents end -->
            </div>
            <!--right end-->
            <div class="clear"></div>
        </div>
    </div>
</div>